<?php

//set plugin id as file name of plugin
$plugin_id = basename(__FILE__);

//some plugin data
$data['name']   = "Comment Plugin";
$data['desc']   = "Modify comment display and add additional email field";
$data['author'] = "John";
$data['url']    = "http://hardkap.net";

//register plugin to SHP
register_plugin($plugin_id, $data);

function comment_function1() {
  global $theme_main, $optionValue, $scriptName, $theme_comment, $public_data, $lang, $config;
  $postid = $public_data['postid'];
  $result = sqlite_query($config['db'], "select * from comments WHERE postid = '$postid' ORDER BY date DESC;");
  while ($row = sqlite_fetch_array($result, SQLITE_ASSOC)) {
      $postid        = $row['postid'];
      $sequence      = $row['sequence'];
      $author        = $row['author'];
      $title         = $row['title'];
      $content       = $row['content'];
      $date          = $row['date'];
      $ip            = $row['ip'];
      $url           = $row['url'];
      $email         = $row['email'];
      $authorLink    = (trim($url) == "")?$author:'<a href="'.$url.'">'.$author.'</a>';
      $theme_comment['sequence']    = $sequence;
      $theme_comment['commentsBy']  = $lang['pageCommentsBy'];
      $theme_comment['authorLink']  = $authorLink;
      $theme_comment['commentDate'] = $lang['pageViewCommentsOn'];
      $theme_comment['date'] = $date;
      $theme_comment['content'] = $content;
      if (isset($_SESSION['logged_in'])?$_SESSION['logged_in']:false) {
          $theme_comment['delete'] = '<a href="'.$_SERVER['SCRIPT_NAME'].'/deleteComment/'.$postid.'/'.$sequence.'">'.$lang['postFtDelete'].'</a>';
          if (isset($_SESSION['isAdmin'])?$_SESSION['isAdmin']:false) {
              $theme_comment['ip'] =  '&nbsp;&nbsp;-&nbsp;&nbsp;'.$ip;
              $theme_comment['ip'].=  '&nbsp;&nbsp;-&nbsp;&nbsp;<a href="mailto:'.$email.'">'.$email.'</a>';
          }
      }
      $theme_main['content'] .= preg_replace("/\{([^\{]{1,100}?)\}/e","$"."theme_comment["."$1"."]",file_get_contents(getcwd()."/themes/".$config['theme']."/blocks/comment.tpl"));
      $i++;
  }
  if ($i == 0) {$theme_main['content'] .= $lang['pageViewCommentsNo']."<br>";}
}

//add hook, where to execute a function
add_hook($plugin_id, 'hook-comment-replace','comment_function1');


?>